package com.cctv.fmaed.module.redis.memory.service.impl;

import com.cctv.fmaed.module.redis.memory.enums.CacheKeyPrefixEnum;
import com.cctv.fmaed.module.redis.memory.pojo.po.UserRegisterPO;
import com.cctv.fmaed.module.redis.memory.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    private StringRedisTemplate stringRedisTemplate;

    public UserServiceImpl(StringRedisTemplate stringRedisTemplate) {
        this.stringRedisTemplate = stringRedisTemplate;
    }

    @Override
    public void putUserRegister(String userId, String nickname) {
        String cacheKeyUserId = CacheKeyPrefixEnum.USER_ID.key(userId);

        UserRegisterPO userRegisterPo = new UserRegisterPO(userId, nickname);

        HashOperations<String, String, String> hashOps = stringRedisTemplate.opsForHash();
        hashOps.putAll(cacheKeyUserId, userRegisterPo);
    }

}
